package com.zzxx.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzxx.mapper.ProductMapper;
import com.zzxx.pojo.Product;
import com.zzxx.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public Product findProductByPK(String id) {
        return productMapper.findById(id);
    }

    @Override
    public PageInfo<Product> getAllProducts(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Product> pageInfo = new PageInfo<>(productMapper.queryAll());
        return pageInfo;
    }

    @Override
    public void deleteById(String id) {
        productMapper.deleteById(id);
    }

    @Override
    public void add(Product product) {
        productMapper.addProduct(product);
    }
}
